/**
* @file componentMatch.h
* @author Alberto Basso, Luca Tumelero
* @brief Set of methods for matching component from target to source cloud
*/

#ifndef COMPONENTMATCH_H
#define COMPONENTMATCH_H

#include "componentSelection.h"
#include "component.h"
#include <math.h>
#include <vector>
#include "pcl/kdtree/kdtree_flann.h"


using namespace std;


/**
 * @brief Find the matching set of points that rapresent the component in source cloud
 *
 * @param[in] registeredSource Input cloud
 * @param[in] componentToFind Component to match into registeredSource
 * @param[out] sourceComponentIndices PointIndices of input cloud's indices
 * @param[in] radius Distance between the points in target and source cloud. First part of the research will be done with radius/5 distance and then with the full radius.
 */
void componentMatch
(
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr registeredSource,
        Component componentToFind,
        PointIndices::Ptr sourceComponentIndices,
        float radius
        );


/**
 * @brief Find the avarage color of a target set of indices
 *
 * @param[in] registeredSource Input cloud
 * @param[in] sourceComponentIndices Indices of the input cloud to be processed
 * @param[out] averageR Avarage Red channel value
 * @param[out] averageG Avarage Green channel value
 * @param[out] averageB Avarage Blue channel value
 */
void getAverageColor
(
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr registeredSource,
        pcl::PointIndices::Ptr sourceComponentIndices,
        int &averageR,
        int &averageG,
        int &averageB
        );
/**
 * @brief Filter points using color property
 *
 * @param[in] cloud Input cloud
 * @param[in] input Indices of the input cloud to be processed
 * @param[out] output Resulting indices of the filtering
 * @param[in] r Avarage Red channel value
 * @param[in] g Avarage Green channel value
 * @param[in] b Avarage Blue channel value
 * @param[in] threshold Threshold for filtering points.
 */
void removeColorOutliers
(
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud,
        pcl::PointIndices::Ptr input,
        pcl::PointIndices::Ptr output,
        int r, int g, int b,
        int threshold
        );

#endif // COMPONENTMATCH_H
